#include <algorithm>        // std::max()
#include <string>           // std::string
#include <vector>           // std::vector
#include <iostream>

using namespace std;

string max_common_substring(const string& s1, const string& s2) {
    size_t m = s1.length();
    size_t n = s2.length();

    vector<size_t> prev(m + 1, 0);
    vector<size_t> curr(m + 1, 0);

    size_t ml = 0;
    size_t e = 0;
    for (size_t i = m; i >= 1; i--) {


        for (size_t j = n; j >= 1; j--) {
            if (s1[i - 1] == s2[j - 1]) {
                curr[j] = prev[j + 1] + 1;
                if (curr[j] > ml) {
                    ml = curr[j];
                    e = i - 1;
                }
            }
            else {
                curr[j] = 0;
            }
        }
        prev = curr;
    }

    if (ml == 0) return "";
    return s1.substr(e, ml);
}

int main()
{
    string s1;
    string s2;
    getline(cin, s1);
    getline(cin, s2);
    cout << max_common_substring(s1, s2) << endl;
    return 0;
}

